home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / visulztn / saoimage / saoimage.lha / grphmove.c < prev    next >
C/C++ Source or Header  |  1990-04-20  |  7KB  |  216 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    grphmove.c (Color Graph Move)
  6.  * Subroutine:    move_cgraph_vertices()        returns: void
  7.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  8.  *        You may do anything you like with this file except remove
  9.  *        this copyright.  The Smithsonian Astrophysical Observatory
  10.  *        makes no representations about the suitability of this
  11.  *        software for any purpose.  It is provided "as is" without
  12.  *        express or implied warranty.
  13.  * Modified:    {0} Michael VanHilst    initial version         11 June 1989
  14.  *        {n} <who> -- <does what> -- <when>
  15.  */
  16.  
  17. #include <X11/Xlib.h>        /* X window stuff */
  18. #include <X11/Xutil.h>        /* X window manager stuff */
  19. #include "hfiles/color.h"    /* color structs */
  20. #include "hfiles/cgraph.h"
  21.  
  22. extern struct cgraphRec cgraph;
  23.  
  24. /*
  25.  * Subroutine:    move_cgraph_vertices
  26.  * Purpose:    Change values (and position) of designated vertices in
  27.  *        response to mouse movement
  28.  */
  29. void move_cgraph_vertices ( x, y )
  30.      int x, y;
  31. {
  32.   double cell_level, intensity;
  33.   int hash_x, hash_y;
  34.   static void move_color_vertex();
  35.  
  36.   /* clip against limits */
  37.   if( x < cgraph.graph.xzero )
  38.     x = cgraph.graph.xzero;
  39.   else if( x > cgraph.graph.xmax )
  40.     x = cgraph.graph.xmax;
  41.   if( y < cgraph.graph.yzero )
  42.     y = cgraph.graph.yzero;
  43.   else if( y > cgraph.graph.ymax )
  44.     y = cgraph.graph.ymax;
  45.   hash_x = x - HASH_RAY;
  46.   hash_y = y - HASH_RAY;
  47.   if( cgraph.vertical ) {
  48.     cell_level = (cgraph.hash.Ymax - (double)hash_y) / cgraph.hash.Yheight;
  49.     intensity = ((double)hash_x - cgraph.hash.Xzero) / cgraph.hash.Xwidth;
  50.   } else {
  51.     cell_level = ((double)hash_x - cgraph.hash.Xzero) / cgraph.hash.Xwidth;
  52.     intensity = (cgraph.hash.Ymax - (double)hash_y) / cgraph.hash.Yheight;
  53.   }
  54.   /* clip against limits */
  55.   if( cell_level < 0.0 )
  56.     cell_level = 0.0;
  57.   else if( cell_level > 1.0 )
  58.     cell_level = 1.0;
  59.   if( intensity < 0.0 )
  60.     intensity = 0.0;
  61.   else if( intensity > 1.0 )
  62.     intensity = 1.0;
  63.   /* move all active vertices */
  64.   if( cgraph.red.active )
  65.     move_color_vertex (&cgraph.red, hash_x, hash_y, cell_level, intensity);
  66.   if( cgraph.green.active )
  67.     move_color_vertex (&cgraph.green, hash_x, hash_y, cell_level, intensity);
  68.   if( cgraph.blue.active )
  69.     move_color_vertex (&cgraph.blue, hash_x, hash_y, cell_level, intensity);
  70. }
  71.  
  72. /*
  73.  * Subroutine:    move_color_vertex
  74.  * Purpose:    Move one ccolor graph vertex
  75.  */
  76. static void move_color_vertex ( col, x, y, new_cell_level, new_intensity )
  77.      struct colgRec *col;
  78.      int x, y;
  79.      double new_cell_level;
  80.      double new_intensity;
  81. {
  82.   int active_hash;
  83.   XRectangle *hash;
  84.  
  85.   active_hash = col->active_hash;
  86.   hash = col->hash;
  87.   if( cgraph.vertical ) {
  88.     if( hash[active_hash].y == y ) {
  89.       /* no change in y (cell_level) */
  90.       if( hash[active_hash].x != x ) {
  91.     hash[active_hash].x = x;
  92.     col->table->intensity[col->active_vertex] = new_intensity;
  93.       }
  94.       return;
  95.     } else {
  96.       /* both x and y changed */
  97.       double *cell_level = col->table->cell_level;
  98.       double *base_level = col->table->base_level;
  99.       double *intensity = col->table->intensity;
  100.       int active_vertex = col->active_vertex;
  101.       int vertex_cnt = col->table->vertex_cnt;
  102.       if( y < hash[active_hash].y ) {
  103.     /* moved up */
  104.     if( (active_vertex < (vertex_cnt - 1)) &&
  105.         (cell_level[active_vertex + 1] < new_cell_level) ) {
  106.       /* position in list must change */
  107.       register int i, j;
  108.       for( i = active_vertex, j = i + 1;
  109.            ((j < vertex_cnt) && (cell_level[j] < new_cell_level));
  110.            i = j, j++ ) {
  111.         cell_level[i] = cell_level[j];
  112.         base_level[i] = base_level[j];
  113.         intensity[i] = intensity[j];
  114.         hash[active_hash].x = hash[active_hash+1].x;
  115.         hash[active_hash].y = hash[active_hash+1].y;
  116.         active_hash++;
  117.       }
  118.       active_vertex = i;
  119.       col->active_vertex = i;
  120.       col->active_hash = active_hash;
  121.     }
  122.       } else {
  123.     /* moved down */
  124.     if( (active_vertex > 0) &&
  125.         (cell_level[active_vertex - 1] > new_cell_level) ) {
  126.       /* position in list must change */
  127.       register int i, j;
  128.       for( i = active_vertex, j = i - 1;
  129.            ((i > 0) && (cell_level[j] > new_cell_level));
  130.            i = j, j-- ) {
  131.         cell_level[i] = cell_level[j];
  132.         base_level[i] = base_level[j];
  133.         intensity[i] = intensity[j];
  134.         hash[active_hash].x = hash[active_hash+1].x;
  135.         hash[active_hash].y = hash[active_hash+1].y;
  136.         active_hash--;
  137.       }
  138.       active_vertex = i;
  139.       col->active_vertex = i;
  140.       col->active_hash = active_hash;
  141.     }
  142.       }
  143.       cell_level[active_vertex] = new_cell_level;
  144.       base_level[active_vertex] =
  145.     (new_cell_level - col->table->bias) / col->table->contrast;
  146.       col->table->intensity[active_vertex] = new_intensity;
  147.       hash[active_hash].x = x;
  148.       hash[active_hash].y = y;
  149.     }
  150.   } else {
  151.     /* horizontal */
  152.     if( hash[active_hash].x == x ) {
  153.       if( hash[active_hash].y != y ) {
  154.     hash[active_hash].y = y;
  155.     col->table->intensity[col->active_vertex] = new_intensity;
  156.       }
  157.       return;
  158.     } else {
  159.       /* cell_level changed */
  160.       double *cell_level = col->table->cell_level;
  161.       double *base_level = col->table->base_level;
  162.       double *intensity = col->table->intensity;
  163.       int active_vertex = col->active_vertex;
  164.       int vertex_cnt = col->table->vertex_cnt;
  165.       if( x > hash[active_hash].x ) {
  166.     /* moved up */
  167.     if( (active_vertex < (vertex_cnt - 1)) &&
  168.         (cell_level[active_vertex + 1] < new_cell_level) ) {
  169.       /* position in list must change */
  170.       register int i, j;
  171.       for( i = active_vertex, j = i + 1;
  172.            ((j < vertex_cnt) && (cell_level[j] < new_cell_level));
  173.            i = j, j++ ) {
  174.         cell_level[i] = cell_level[j];
  175.         base_level[i] = base_level[j];
  176.         intensity[i] = intensity[j];
  177.         hash[active_hash].x = hash[active_hash+1].x;
  178.         hash[active_hash].y = hash[active_hash+1].y;
  179.         active_hash++;
  180.       }
  181.       active_vertex = i;
  182.       col->active_vertex = i;
  183.       col->active_hash = active_hash;
  184.     }
  185.       } else {
  186.     /* moved down */
  187.     if( (active_vertex > 0) &&
  188.         (cell_level[active_vertex - 1] > new_cell_level) ) {
  189.       /* position in list must change */
  190.       register int i, j;
  191.       for( i = active_vertex, j = i - 1;
  192.            ((i > 0) && (cell_level[j] > new_cell_level));
  193.            i = j, j-- ) {
  194.         cell_level[i] = cell_level[j];
  195.         base_level[i] = base_level[j];
  196.         intensity[i] = intensity[j];
  197.         hash[active_hash].x = hash[active_hash+1].x;
  198.         hash[active_hash].y = hash[active_hash+1].y;
  199.         active_hash--;
  200.       }
  201.       active_vertex = i;
  202.       col->active_vertex = i;
  203.       col->active_hash = active_hash;
  204.     }
  205.       }
  206.       cell_level[active_vertex] = new_cell_level;
  207.       base_level[active_vertex] =
  208.     (new_cell_level - col->table->bias) / col->table->contrast;
  209.       col->table->intensity[active_vertex] = new_intensity;
  210.       hash[active_hash].x = x;
  211.       hash[active_hash].y = y;
  212.     }
  213.   }
  214.   col->unset = 1;
  215. }
  216.